package com.jingzhe.core.constant;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.google.common.collect.Maps;
import com.jingzhe.core.utils.PropertiesUtil;

/**
 * 全局变量
 * @author wanghj
 *
 */
public class GlobalConstant {
    /**
     * 当前对象实例
     */
    private static GlobalConstant globalConstant = new GlobalConstant();
    
    /**
     * 保存全局属性值
     */
    private static Map<String, String> map = Maps.newHashMap();
    
    /**
     * 属性文件加载对象
     */
    private static PropertiesUtil loader = new PropertiesUtil("jingzhe.properties");
    
    /**
     * 是/否
     */
    public static final String YES = "1";
    public static final String NO = "0";
    
    /**
     * 对/错
     */
    public static final String TRUE = "true";
    public static final String FALSE = "false";
    
    /**
     * 获取当前对象实例
     */
    public static GlobalConstant getInstance() {
        return globalConstant;
    }
    
    /**
     * 获取配置
     */
    public static String getConfig(String key) {
        String value = map.get(key);
        if (value == null){
            value = loader.getProperty(key);
            map.put(key, value != null ? value : StringUtils.EMPTY);
        }
        return value;
    }
    
    /**
     * 获取URL后缀
     */
    public static String getUrlSuffix() {
        return getConfig("urlSuffix");
    }
}
